package com.qf.controller;

import com.qf.entity.Result;
import com.qf.mapper.SetMealMapper;
import com.qf.pojo.Setmeal;
import com.qf.service.SetMealService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetMealController {

    @Resource
    SetMealMapper setMealMapper;
    @Autowired
    SetMealService setMealService;

    /**
     * 获得所有套餐信息
     */
    @RequestMapping("/getSetMeal")
    public Result getSetMeal(){
        try{
            List<Setmeal> setmealList = setMealMapper.selectList(null);
            return Result.success(setmealList);
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("失败");
            return Result.error("查询失败");
        }
    }
    /**
     * 从前端得到套餐的id
     * 根据套餐id得到套餐信息
     */
    @RequestMapping("/findById")
    public Result findById(Integer id){
        try{
            Setmeal setmeal = setMealService.findById(id);
            return  Result.success(setmeal);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error("失败");
        }
    }
}
